April 7, 2012, 1:32 am
#include <iostream>
#include <string>
using namespace std;
bool check(string palendrome) {
size_t limit=0;
if(palendrome.size()%2 == 0) limit = palendrome.size()/2;
else limit = (palendrome.size()-1)/2;
for(size_t n=0;n<limit;n++) {
if(palendrome[n] != palendrome[palendrome.size()-n-1]) return false;
}
return true;
}
int main() {
string palendrome1 = "catac";
bool check1 = check(palendrome1); if(check1 == true) cout << palendrome1 << " is palendromic" << endl; else cout << palendrome1 << " is not palendromic" << endl;
string palendrome2 = "caac";
bool check2 = check(palendrome2); if(check2 == true) cout << palendrome2 << " is palendromic" << endl; else cout << palendrome2 << " is not palendromic" << endl;
string palendrome3 = "zcaacr";
bool check3 = check(palendrome3); if(check3 == true) cout << palendrome3 << " is palendromic" << endl; else cout << palendrome3 << " is not palendromic" << endl;
}